package c.e.b.h.e.p;

import android.app.ActivityManager.RunningAppProcessInfo;
import c.e.b.h.e.t.e;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

/* compiled from: SessionProtobufHelper */
public class d {
    public static final a a = a.a("0");
    public static final a b = a.a("Unity");

    public static int a(a aVar, a aVar2) {
        int b = c.b(3, aVar) + (c.k(2, 0) + (c.k(1, 0) + 0));
        return aVar2 != null ? b + c.b(4, aVar2) : b;
    }

    public static int b(String str, String str2) {
        int b = c.b(1, a.a(str));
        if (str2 == null) {
            str2 = "";
        }
        return c.b(2, a.a(str2)) + b;
    }

    public static int c(e eVar, int i, int i2) {
        int i3 = 0;
        int b = c.b(1, a.a(eVar.b)) + 0;
        String str = eVar.a;
        if (str != null) {
            b += c.b(3, a.a(str));
        }
        for (StackTraceElement h : eVar.c) {
            int h2 = h(h, true);
            b += (c.d(h2) + c.f(4)) + h2;
        }
        eVar = eVar.d;
        if (eVar == null) {
            return b;
        }
        if (i < i2) {
            int c = c(eVar, i + 1, i2);
            return b + ((c.d(c) + c.f(6)) + c);
        }
        while (eVar != null) {
            eVar = eVar.d;
            i3++;
        }
        return b + c.i(7, i3);
    }

    public static int d() {
        a aVar = a;
        return c.k(3, 0) + (c.b(2, aVar) + (c.b(1, aVar) + 0));
    }

    public static int e(e eVar, Thread thread, StackTraceElement[] stackTraceElementArr, Thread[] threadArr, List<StackTraceElement[]> list, int i, a aVar, a aVar2) {
        int f = c.f(1);
        int i2 = i(thread, stackTraceElementArr, 4, true);
        int d = ((c.d(i2) + f) + i2) + 0;
        int length = threadArr.length;
        for (int i3 = 0; i3 < length; i3++) {
            int i4 = i(threadArr[i3], (StackTraceElement[]) list.get(i3), 0, false);
            d += (c.d(i4) + f) + i4;
        }
        int c = c(eVar, 1, i);
        int d2 = ((c.d(c) + c.f(2)) + c) + d;
        c = d();
        int d3 = ((c.d(c) + c.f(3)) + c) + d2;
        c = a(aVar, aVar2);
        return ((c.d(c) + c.f(3)) + c) + d3;
    }

    public static int f(e eVar, Thread thread, StackTraceElement[] stackTraceElementArr, Thread[] threadArr, List<StackTraceElement[]> list, int i, a aVar, a aVar2, Map<String, String> map, RunningAppProcessInfo runningAppProcessInfo, int i2) {
        int e = e(eVar, thread, stackTraceElementArr, threadArr, list, i, aVar, aVar2);
        boolean z = true;
        int d = ((c.d(e) + c.f(1)) + e) + 0;
        if (map != null) {
            for (Entry entry : map.entrySet()) {
                int b = b((String) entry.getKey(), (String) entry.getValue());
                d += (c.d(b) + c.f(2)) + b;
            }
        }
        if (runningAppProcessInfo != null) {
            if (runningAppProcessInfo.importance == 100) {
                z = false;
            }
            d += c.a(3, z);
        }
        return c.i(4, i2) + d;
    }

    public static int g(Float f, int i, boolean z, int i2, long j, long j2) {
        int i3 = 0;
        if (f != null) {
            f.floatValue();
            i3 = 0 + (c.f(1) + 4);
        }
        return c.k(6, j2) + (c.k(5, j) + (c.i(4, i2) + (c.a(3, z) + (i3 + (c.d((i >> 31) ^ (i << 1)) + c.f(2))))));
    }

    public static int h(StackTraceElement stackTraceElement, boolean z) {
        int k;
        int i = 0;
        if (stackTraceElement.isNativeMethod()) {
            k = c.k(1, (long) Math.max(stackTraceElement.getLineNumber(), 0));
        } else {
            k = c.k(1, 0);
        }
        k += 0;
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(stackTraceElement.getClassName());
        stringBuilder.append(".");
        stringBuilder.append(stackTraceElement.getMethodName());
        int b = c.b(2, a.a(stringBuilder.toString())) + k;
        if (stackTraceElement.getFileName() != null) {
            b += c.b(3, a.a(stackTraceElement.getFileName()));
        }
        if (!stackTraceElement.isNativeMethod() && stackTraceElement.getLineNumber() > 0) {
            b += c.k(4, (long) stackTraceElement.getLineNumber());
        }
        if (z) {
            i = 2;
        }
        return c.i(5, i) + b;
    }

    public static int i(Thread thread, StackTraceElement[] stackTraceElementArr, int i, boolean z) {
        i = c.i(2, i) + c.b(1, a.a(thread.getName()));
        for (StackTraceElement h : stackTraceElementArr) {
            int h2 = h(h, z);
            i += (c.d(h2) + c.f(3)) + h2;
        }
        return i;
    }

    public static a j(String str) {
        return str == null ? null : a.a(str);
    }

    public static void k(c cVar, int i, StackTraceElement stackTraceElement, boolean z) throws Exception {
        cVar.r((i << 3) | 2);
        cVar.r(h(stackTraceElement, z));
        int i2 = 0;
        if (stackTraceElement.isNativeMethod()) {
            cVar.v(1, (long) Math.max(stackTraceElement.getLineNumber(), 0));
        } else {
            cVar.v(1, 0);
        }
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(stackTraceElement.getClassName());
        stringBuilder.append(".");
        stringBuilder.append(stackTraceElement.getMethodName());
        cVar.o(2, a.a(stringBuilder.toString()));
        if (stackTraceElement.getFileName() != null) {
            cVar.o(3, a.a(stackTraceElement.getFileName()));
        }
        if (!stackTraceElement.isNativeMethod() && stackTraceElement.getLineNumber() > 0) {
            cVar.v(4, (long) stackTraceElement.getLineNumber());
        }
        if (z) {
            i2 = 4;
        }
        cVar.u(5, i2);
    }

    public static void l(c cVar, e eVar, int i, int i2, int i3) throws Exception {
        cVar.r((i3 << 3) | 2);
        cVar.r(c(eVar, 1, i2));
        cVar.o(1, a.a(eVar.b));
        String str = eVar.a;
        if (str != null) {
            cVar.o(3, a.a(str));
        }
        int i4 = 0;
        for (StackTraceElement k : eVar.c) {
            k(cVar, 4, k, true);
        }
        eVar = eVar.d;
        if (eVar == null) {
            return;
        }
        if (i < i2) {
            l(cVar, eVar, i + 1, i2, 6);
            return;
        }
        while (eVar != null) {
            eVar = eVar.d;
            i4++;
        }
        cVar.u(7, i4);
    }

    public static void m(c cVar, Thread thread, StackTraceElement[] stackTraceElementArr, int i, boolean z) throws Exception {
        cVar.t(1, 2);
        cVar.r(i(thread, stackTraceElementArr, i, z));
        cVar.o(1, a.a(thread.getName()));
        cVar.u(2, i);
        for (StackTraceElement k : stackTraceElementArr) {
            k(cVar, 3, k, z);
        }
    }
}
